/*
 * @Date: 2024-11-14 09:59:11
 * @Author: LiSong
 * @LastEditors: LiSong
 * @LastEditTime: 2024-11-14 09:59:13
 * @Description: 数据源类型
 */

import { PojoUtils } from '../cfg/PojoUtils'

/* 
  表格数据源类型 数据源模式选择数据
 */
export class DataSourceType {
  constructor(name, value) {
    this.name = name;
    this.value = value
  }
  static get SQL() {
    return new DataSourceType('SQL数据', 'SQL')
  }
  static get REQ() {
    return new DataSourceType('接口数据', 'REQ')
  }
  static get STA() {
    return new DataSourceType('静态数据', 'STA')
  }
  getPkg() {
    if (this.value === 'SQL') {
      return { value: this.value, label: { en: 'SQL', zh: '数据' } }
    }
    if (this.value === 'REQ') {
      return { value: this.value, label: { en: '', zh: '接口数据' } }
    }
    if (this.value === 'STA') {
      return { value: this.value, label: { en: '', zh: '静态数据' } }
    }
  }
  equals(value) {
    if (value instanceof DataSourceType) {
      return value.value === this.value
    } else {
      return value === this.value
    }
  }
}

export class DataSourceTypes {
  static getData() {
    const staticKeys = PojoUtils.getOwnPropertyStatics(DataSourceType)
    const staticItems = staticKeys.map(key => DataSourceType[key])
    return staticItems
  }
}
